package org.drushpal.view.tabs
{
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import mx.binding.utils.BindingUtils;
	import mx.collections.ArrayCollection;
	import mx.events.FlexEvent;
	
	import org.drushpal.model.RepositoryModel;
	import org.drushpal.model.enum.DrushCommand;
	import org.drushpal.model.vo.Project;
	import org.drushpal.service.DrushService;
	import org.drushpal.util.LinkEvent;
	import org.robotlegs.mvcs.Mediator;
	
	public class ModulesTabMediator extends Mediator
	{
		[Inject]public var modulesTab:ModulesTab;
		[Inject]public var drushService:DrushService;
		[Inject]public var repositoryModel:RepositoryModel;
		
		override public function onRegister():void{
			drushService.run(DrushCommand.LIST); 
			eventMap.mapListener(modulesTab,ModulesTab.EVENT_QUICK_DL,onQuickDL);
			modulesTab.availableProjects = repositoryModel.availableProjects;
			BindingUtils.bindProperty(modulesTab,"projectsCollection",drushService,"projectsCollection");
		}
		private function onQuickDL(event:Event):void{
			var args:Array = new Array();
			for each(var project:Project in modulesTab.acProjects.selectedItems){
				args.push(project.short_name);
			}
			drushService.run(DrushCommand.DOWNLOAD,args);
			modulesTab.acProjects.selectedItems = new ArrayCollection();
			modulesTab.currentState = 'normal';
		}
	}
}